import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] mat = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                mat[i][j] = scanner.nextInt();
            }
        }
        int[] nums = clockwisePrint(mat,n,m);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
    }
    public static int[] clockwisePrint(int[][] mat, int n, int m) {
        // write code here
        int top = 0;
        int bootom = n - 1;
        int left = 0;
        int right = m - 1;
        int[] nums = new int[n * m];
        int i = 0;
        while (top <= bootom && left <= right) {
            for (int j = left; j < right ; j++) {
                nums[i] = mat[top][j];
                i++;
            }
            for (int j = top; j < bootom ; j++) {
                nums[i] = mat[j][right];
                i++;
            }
            for (int j = right; j > left ; j--) {
                nums[i] = mat[bootom][j];
                i++;
            }
            for (int j = bootom; j > top ; j--) {
                nums[i] = mat[j][left];
                i++;
            }
            if(top == bootom && left == right){
                nums[i] = mat[top][left];

            }
            left ++;
            right--;
            top++;
            bootom--;
        }
        return nums;
    }
}
